package com.hualan.controller;

import com.github.pagehelper.PageInfo;
import com.hualan.pojo.ConsultFeedback;
import com.hualan.pojo.Result;
import com.hualan.service.ConsultFeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/hdx")
public class ConsultFeedbackController {
    @Autowired
    private ConsultFeedBackService consultFeedBackService;

    @GetMapping("/find")
    public Result selectByType(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize, String type){
        PageInfo<ConsultFeedback> byType = consultFeedBackService.findByType(pageNum, pageSize, type);
        return Result.success(byType);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id){
        int i = consultFeedBackService.deleteFeedback(id);
        if (i != 0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }
    @PostMapping("/insert")
    public Result insert(@RequestBody ConsultFeedback consultFeedback){
        int i = consultFeedBackService.insertFeedback(consultFeedback);
        if (i != 0){
            return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }
    @DeleteMapping("/batchs")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        int i = consultFeedBackService.deleteBatch(ids);
        if (i != 0){
            return Result.success("批量删除成功");
        }
        return Result.error("批量删除失败");
    }
    @GetMapping("/update")
    public Result updateFeedback(Integer id,String feedback){
        int i = consultFeedBackService.updateFeedback(id, feedback);
        if (i != 0){
            return Result.success("回复修改成功");
        }
        return Result.error("回复修改失败");
    }
}
